package com.tl.commonlibrary.ui.widget;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tl.commonlibrary.R;
import com.tl.commonlibrary.ui.BaseFragmentActivity;
import com.tl.commonlibrary.ui.widget.loopview.LoopView;
import com.tl.commonlibrary.ui.widget.loopview.OnItemSelectedListener;

import java.util.ArrayList;
import java.util.List;

import razerdp.basepopup.BasePopupWindow;

/**
 * IndustryTypePop
 *
 * @author lisi
 * @Describe 行业选择分类pop
 * @time 2017/5/23 11:42
 **/

public class IndustryTypePop extends BasePopupWindow {

//    TextView dialogContent;

    Button dialogCancel;

    Button dialogConfirm;
    Context context;

    public OnPopClickListener getOnPopClickListener() {
        return onPopClickListener;
    }

    public void setOnPopClickListener(OnPopClickListener onPopClickListener) {
        this.onPopClickListener = onPopClickListener;
    }

    OnPopClickListener onPopClickListener;

//    public ArrayList<String> arrayList;
    LoopView dialogOneWheel;
//    LinearLayout popupAnima;

    public String selectStr = "";

    public IndustryTypePop(Activity context, final List<String> arrayList) {
        super(context, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        this.context = context;
        dialogCancel = (Button) findViewById(R.id.btnCancel);
        dialogConfirm = (Button) findViewById(R.id.btnSubmit);
        dialogOneWheel = (LoopView) findViewById(R.id.dialog_one_wheelview);
        dialogOneWheel.setNotLoop();
        //设置数据
        dialogOneWheel.setItems(arrayList);

        selectStr = arrayList.get(0);

        dialogOneWheel.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                if (arrayList != null) {
                    selectStr = arrayList.get(index);
                }
            }
        });
        dialogCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onPopClickListener != null) {
                    onPopClickListener.onPopCancelClick(v);
                }
                dismiss();
            }
        });


        dialogConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onPopClickListener != null) {
                    onPopClickListener.onPopConfirmClick(selectStr);

                }
                dismiss();
            }
        });
    }

    @Override
    protected Animation initShowAnimation() {

        return null;
    }

    @Override
    public void showPopupWindow() {
        super.showPopupWindow();
        InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive())
            imm.hideSoftInputFromWindow(((BaseFragmentActivity)context).getWindow().getDecorView().getWindowToken(), 0); //强制隐藏键盘
    }

    @Override
    public View getClickToDismissView() {
        return null;
    }

    @Override
    public View onCreatePopupView() {
        return createPopupById(R.layout.dialog_type_wheelview_pop);
    }

    @Override
    public View initAnimaView() {
        return findViewById(R.id.dialog_popup_anima);
    }


    //监听器
    public interface OnPopClickListener {
        //确认
        void onPopConfirmClick(String itemstr);

        //取消
        void onPopCancelClick(View view);
    }
}
